
package com.example.quicklaunch;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.RemoteViews;

public class QuickLaunchWidgetProvider extends AppWidgetProvider {
    private final int[] IDS = new int[] {
            R.id.one, R.id.two, R.id.three,
            R.id.four, R.id.five, R.id.six, R.id.seven, R.id.eight, R.id.nine, R.id.zero, R.id.delete
    };
    private static final String BUTTON_ACTION = "com.example.quicklaunch.BUTTON_CLICK";
    public static final String EXTRA_CLICK_ID = "clicked_id";

    private PendingIntent getPendingIntent(Context paramContext, int paramInt1, int paramInt2)
    {
      Intent localIntent = new Intent(BUTTON_ACTION);
      localIntent.putExtra(EXTRA_CLICK_ID, paramInt2);
      return PendingIntent.getService(paramContext, 1, localIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    }

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        for (int appWidgetId : appWidgetIds) {
            RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
                    R.layout.activity_main);
            for(int id : IDS) {
                remoteViews.setOnClickPendingIntent(id, getPendingIntent(context, appWidgetId, id));
            }
            appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
        }
        Intent localIntent = new Intent(BUTTON_ACTION);
        context.startService(localIntent);
    }

    @Override
    public void onEnabled(Context context) {
        super.onEnabled(context);
    }

    @Override
    public void onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager,
            int appWidgetId, Bundle newOptions) {
        super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions);
    }
}
